// index.js
// 获取应用实例
import Toast from '@vant/weapp/toast/toast';
import voice from '../../utils/voice'
Page({
  data: {
    checked: false,
    cloth: '',
    user: 'none',
    userInfo: {},
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 检查版本支持
  },
  onChange({
    detail
  }) {
    // 需要手动对 checked 状态进行更新
    console.log('是否静音', detail);
    wx.setStorage({
      data: detail,
      key: "mute",
    })
    let content = ''
    if (detail) {
      content = ''
      Toast('关闭音频')
    } else {
      content = '开启音频'
      Toast(content)
    }
    voice.wordYun(content)
    console.log('detail', detail);
    this.setData({
      checked: detail
    });

  },
  getuser() {
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        let user = res.userInfo;
        wx.setStorageSync('user', user)
        console.log(res.user)
        this.setData({
          cloth: 'none',
          user: '',
        })
      },
      fail: res => {
        console.log('授权失败'), res;
      }
    })
  },
  // 退出登录
  exit() {
    wx.setStorageSync('user', '')
    this.setData({
      cloth: '',
      user: 'none',
    })

  },
  // 事件处理函数
  bindViewTap() {

    Toast('欢迎您！', name)
  },
  onShow() {
    this.getTabBar().init();

  },
  onLoad() {
    let mute = wx.getStorageSync('mute')
    if (mute == false) {
      this.setData({
        checked: mute
      })
    } else {
      this.setData({
        checked: true
      })
    }
    let user = wx.getStorageSync('user')
    if (user !== '') {
      this.setData({
        cloth: 'none',
        user: '',
      })
    }
  },
})